package com.boot_reggie.Service.impl;

import com.boot_reggie.Service.SendMeilService;
import com.boot_reggie.common.CheckCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.soap.Addressing;
@Service
public class SendMailServiceimpl implements SendMeilService {
    @Autowired
    private JavaMailSender javaMailSender;
//发送人
    private String from = "2624636142@qq.com";
//    接收人
    private String to = "2624636142@qq.com";
//    标题
    private String title = "";
//    正文
    private String context = "您的验证码是";
    @Override
    public String Context(String name,String title,HttpSession session) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(name);
        simpleMailMessage.setSubject(title);
        String code = CheckCodeUtil.generateVerifyCode(4);
        session.setAttribute("code",code);
        simpleMailMessage.setText(context + code);
        session.setMaxInactiveInterval(600);
        javaMailSender.send(simpleMailMessage);
        return code;
    }
}
